package qiniu

import (
	"github.com/qiniu/go-sdk/v7/auth"
	"github.com/qiniu/go-sdk/v7/storage"
	"lianzi_gos/internal/config"
)

func GetQiniuToken() interface{} {
	accessKey := config.C.Qiniu.Access
	secretKey := config.C.Qiniu.Secret
	bucket := config.C.Qiniu.Bucket
	expires := config.C.Qiniu.Exp
	uploadApi := config.C.Qiniu.Upload

	mac := auth.New(accessKey, secretKey)

	// 设置上传凭证有效期
	putPolicy := storage.PutPolicy{
		Scope:   bucket,
		Expires: expires,
	}
	upToken := putPolicy.UploadToken(mac)
	data := make(map[string]string)
	data["url"] = uploadApi
	data["token"] = upToken
	return data
}
